<?php
require_once('../config/auth.php');
require_once('employe.cl.php');
$__CURRENT_PAGE__ = 'employe';
$__TITLE__ = "Fromulaire de modification des ordres des employés";
$employe = new Employe();
if(!empty($_POST['order'])) {
   $employe->saveOrder($_POST['order']);
   $message = "<div class='alert alert-success' class='span4'>Ordre de garde sauvegardé avec succès</div>";
}
$serviceId = empty($_GET['service_id']) ? 0 : $_GET['service_id'];
$type = empty($_GET['type']) ? 0 : $_GET['type'];
$employes = $employe->getEmployesByServiceIdAndType($serviceId, $type);
$departements = $employe->getService()->getDepartement()->getAllDepartements();

if(!empty($_GET['service_id'])) {
  $employe->getService()->loadServiceById($_GET['service_id']);
  $services = $employe->getService()->getServiceByDepartementId($employe->getService()->getDepartementId());
} else {
  $services = $employe->getService()->getAllServices();
}

require_once(dirname(__FILE__).'/../config/head.php');?>
<body>
<?php require_once(dirname(__FILE__).'/../config/menu.php'); ?>
<div class="container employeList">
<h1>Modification de l'ordre des gardes</h1>
 <form method="post" class="form">
 <input type="hidden" name="id" value="<?php echo $employe->getId() ?>" />
    <select name="departement_id" id="departement_id">
          <option value="">--Selectionner un departement--</option>
          <?php foreach($departements as $depart): ?>
            <option <?php echo ($employe->getService()->getDepartementId() == $depart->id)  ? 'selected="selected"' : '' ?>
            value="<?php echo $depart->id?>"><?php echo $depart->name ?></option>   
          <?php endforeach ?>
  </select>
  <select name="service_id" id="service_id">
          <option value="">--Selectionner un service--</option>
          <?php foreach($services as $serv): ?>
            <option <?php echo ($employe->getService()->getId() == $serv->id)  ? 'selected="selected"' : '' ?>
            value="<?php echo $serv->id?>"><?php echo $serv->name ?></option>   
          <?php endforeach ?>
  </select>
  <select name="type" id="type">
          <option value="">--Selectionner un type--</option>
          <option <?php echo ($employe->getType()=="Ingenieur")  ? 'selected="selected"' : '' ?> value="Ingenieur">Ingenieur</option>
          <option <?php echo ($employe->getType()=="Agent")  ? 'selected="selected"' : '' ?> value="Agent">Agent</option>
  </select>
  <table class="table table-striped" width="500" aling="center">
    <thead>
      <tr><th>Matricule</th><th>Nom</th><th>Prénom</th><th>Ordre</th></tr>
    </thead>     
        <tbody>
          <?php foreach($employes as $emp):?>
                <tr>
                  <td><?php echo $emp->matricule?></td><td><?php echo $emp->last_name?></td><td><?php echo $emp->first_name?></td><td><input type="text" name="order[<?php echo $emp->id?>]" class ="input-mini" size="50" maxlength="50" value="<?php echo $emp->order?>"></td>
                </tr>
            <?php endforeach ?>
        </tbody>
  </table>
  <div class="row">
     <div class="span2 offset8">
         <input type="submit" value="Valider" class="btn btn-success btn-large btn-block">
     </div>
 </div>
</form>
</div>
</body>
